var express = require('express');
var router = express.Router();
var prodDao = require('../dao/prodDao')
var db = require('../config/basicConnection');
var $sqlCommands = require('../config/sqlCommand');

var formidable = require('formidable'),
    fs = require('fs');

/**
 * 用户增加的路由控制接口
 */

router.get('/', function(req, res, next) {
    res.render('product', { title: '' });
});
router.post('/findAllAction', function(req, res, next) {
    prodDao.findAllAction(req,res,next)
});

router.post('/findByName', function(req, res, next) {
    prodDao.findByName(req,res,next)
});

router.post('/updateById',function(req,res,next){
    // console.log(req.body)
    prodDao.updateById(req,res,next)
});

router.post('/insertOne',function(req,res,next){
    // console.log(req.body)
    prodDao.insertOne(req,res,next)
});

router.post('/deteleProdById',function(req,res,next){
    // console.log(req.body)
    prodDao.deteleProdById(req,res,next)
});

router.post('/findSpecItem',function(req,res,next){
    // console.log(req.body)
    prodDao.findSpecItem(req,res,next)
});

router.post('/findSpec',function(req,res,next){
    // console.log(req.body)
    prodDao.findSpec(req,res,next)
});
router.post('/findOneById',function(req,res,next){
    // console.log(req.body)
    prodDao.findOneById(req,res,next)
});

router.post('/findSpec',function(req,res,next){
    // console.log(req.body)
    prodDao.findSpec(req,res,next)
});

router.post('/insertOneSpec',function(req,res,next){
    // console.log(req.body)
    prodDao.insertOneSpec(req,res,next)
});

router.post('/updateIconById',function(req,res,next){
    // console.log(req.body)
    prodDao.updateIconById(req,res,next)
});

router.post('/updateByIdNophoto',function(req,res,next){
    // console.log(req.body)
    prodDao.updateByIdNophoto(req,res,next)
});

router.post('/up',function(req,res,next){
    // console.log(req.body)
    prodDao.up(req,res,next)
    // var up='';
    // var form = formidable.IncomingForm({
    //     encoding: 'utf-8',//上传编码
    //     uploadDir: "X:/WebstormProjects/webizz/public/files/prod/",//上传目录，指的是服务器的路径，如果不存在将会报错。
    //     keepExtensions: true,//保留后缀
    //     // maxFieldsSize: 2 * 1024 * 1024//byte//最大可上传大小
    // });
    // form.parse(req,function(error, fields, files) {
    //     console.log(files)
    //     var types = files.file.name.split('.');
    //     var date = new Date();
    //     var ms = Date.parse(date);
    //     var newName = ms + "." + String(types[types.length - 1])
    //     var user = fields
    //     up = form.uploadDir + newName
    //     // console.log(up)
    //     fields.icon = form.uploadDir + newName
    //     var name = "../" + up.split('/')[up.split('/').length - 2] + '/' + up.split('/')[up.split('/').length - 1]
    //     // console.log(name)
    //     fs.renameSync(files.file.path, form.uploadDir + newName);
    //     // console.log(fields)
    // })
});

module.exports = router;
